package com.situ.mall.user.controller;


import com.situ.mall.common.util.Result;
import com.situ.mall.pojo.entity.user.Address;
import com.situ.mall.user.service.IAddressService;
import com.situ.mall.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户地址表 前端控制器
 * </p>
 *
 * @author Sun Huijuan
 * @since 2024-10-14
 */
@RestController
@RequestMapping("/user/address")
public class AddressController {
	@Autowired
	private IAddressService addressService;
	
	@GetMapping("/selectByUserId/{id}")
	public Result<List<Address>> selectByUserId(@PathVariable Integer id) {
		List<Address> list=addressService.selectByUserId(id);
		return Result.ok(list);
	}
	
	@PostMapping("/add")
	public Result add(@RequestBody Address address) {
		addressService.save(address);
		return Result.ok("添加成功！");
	}
	
	@DeleteMapping("/deleteById/{id}")
	public Result deleteById(@PathVariable Integer id) {
		addressService.removeById(id);
		return Result.ok("删除成功！");
	}
	
	@GetMapping("/selectById/{id}")
	public Result<Address> selectById(@PathVariable Integer id) {
		Address address=addressService.getById(id);
		return Result.ok(address);
	}

}

